// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SA1119StatementMustNotUseUnnecessaryParenthesisBulbItem.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Defines the SA1119StatementMustNotUseUnnecessaryParenthesisBulbItem type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace StyleCop.For.ReSharper.BulbItems.Maintainability
{
    #region Using Directives

    using JetBrains.ProjectModel;
    using JetBrains.ReSharper.Psi.CSharp.Tree;
    using JetBrains.TextControl;

    using StyleCop.For.ReSharper.BulbItems.Framework;
    using StyleCop.For.ReSharper.CodeCleanup.Rules;
    using StyleCop.For.ReSharper.Core;

    #endregion

    internal class SA1119StatementMustNotUseUnnecessaryParenthesisBulbItem : V5BulbItemImpl
    {
        public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl)
        {
            var tokensForLine = Utils.GetTokensForLineFromTextControl(solution, textControl);

            foreach (var tokenNode in tokensForLine)
            {
                var parenthesizedExpressionNode = tokenNode.GetContainingElement<IParenthesizedExpressionNode>(true);
                MaintainabilityRules.RemoveParenthesisFromNode(parenthesizedExpressionNode);
            }
        }
    }
}